package com.sh.data.engine.web.webapi.controller.dataquality;

import com.sh.data.engine.application.model.dto.base.PagerResponse;
import com.sh.data.engine.application.model.dto.dataquality.DataQualityJobResponse;
import com.sh.data.engine.application.model.request.dataquality.DataQualityTaskRequest;
import com.sh.data.engine.application.service.dataquality.DataQualityJobApplicationService;
import com.sh.data.engine.domain.base.model.PageResult;
import com.sh.data.engine.domain.dataquality.model.domain.DataQualityJobRuleDetailDomain;
import com.sh.data.engine.domain.dataquality.model.domain.DataqualityJobMonitorDomain2;
import com.sh.data.engine.web.webapi.controller.base.response.RestResponseEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author tinglan.ys
 * @description: 数据质量-任务管理相关API
 * @date 2022/2/15 下午6:05
 */
@Validated
@RestController
@RequestMapping("/dataQuality/job")
@Tag(name = "数据质量-任务管理", description = "数据质量-任务管理相关API")
public class DataQualityJobController {

    @Autowired
    private DataQualityJobApplicationService dataQualityJobApplicationService;

    //    @AuthorityAnnotation(menuId = MenuEnumNew.RWGL, readWriteStatus = 0, isAdd = 1)
    @GetMapping("/getJobs")
    @Operation(summary = "获取任务列表")
    public RestResponseEntity<PagerResponse<DataQualityJobResponse>> getJobs(
        @Valid DataQualityTaskRequest request) {
        var result = dataQualityJobApplicationService.getJobs(request);
        return RestResponseEntity.success(result);
    }

    //    @AuthorityAnnotation(menuId = MenuEnumNew.RWGL, readWriteStatus = 0, isAdd = 1)
    @GetMapping("/getJobRuleDetail")
    @Operation(summary = "获取任务规则详情")
    public RestResponseEntity<PageResult<DataQualityJobRuleDetailDomain>> getJobRuleDetail(
        @Parameter(description = "任务id", required = true) @RequestParam Long jobId,
        @Parameter(description = "第几页") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
        @Parameter(description = "每页大小") @RequestParam(required = false, defaultValue = "15")
        Integer pageSize) {
        var result = dataQualityJobApplicationService.getJobRuleDetail(jobId, pageNum, pageSize);
        return RestResponseEntity.success(result);
    }

    //    @AuthorityAnnotation(menuId = MenuEnumNew.RWGL, readWriteStatus = 0, isAdd = 1)
    @GetMapping("/getJobRuleFields")
    @Operation(summary = "获取任务规则所有字段详情-监控结果列表页")
    public RestResponseEntity<PageResult<DataqualityJobMonitorDomain2>> getJobRuleFields(
        @Parameter(description = "任务id", required = true) @RequestParam Long jobId,
        @Parameter(description = "第几页") @RequestParam(required = false, defaultValue = "1") Integer pageNum,
        @Parameter(description = "每页大小") @RequestParam(required = false, defaultValue = "15")
        Integer pageSize) {
        var result = dataQualityJobApplicationService.getJobRuleFields(jobId, pageNum, pageSize);
        return RestResponseEntity.success(result);
    }
}
